﻿using Autofac;
using Autofac.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xant.FlowEngine.Interface;

namespace Xant.FlowEngine
{
    public class AutofacDemo
    {
        private IOrganizationLocator organizLocator;
        public AutofacDemo(IOrganizationLocator locator)
        {
            this.organizLocator = locator;
        }

        public IOrganization QueryOrganization(object id)
        {
            return organizLocator.FindOrganization(id);
        }

        public static AutofacDemo GetInstance()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<AutofacDemo>();
            builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
            using (var container = builder.Build())
            {
                var instance = container.Resolve<AutofacDemo>();
                var organ = instance.QueryOrganization("00000001-0000-0000-0000-000000000000");
                return instance;
            }
        }
    }
}
